﻿using DataScripter.Excel.Formulas;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace DataScripter.Excel.UnitTests
{
    [TestClass]
    public class OperatorTests
    {
        [TestMethod]
        public void TestAdd()
        {
            Reference ref1 = new Reference("A21");
            Reference ref2 = new Reference("B21");
            Formula formula = ref1 + ref2;
            Mock<ICell> cellMock = new Mock<ICell>(MockBehavior.Strict);
            Assert.AreEqual("A21+B21", formula.Resolve(cellMock.Object));
        }
        [TestMethod]
        public void TestDoubleAdd()
        {
            Reference ref1 = new Reference("A21");
            Reference ref2 = new Reference("B21");
            Reference ref3 = new Reference("C21");
            Formula formula = ref1 + ref2 + ref3;
            Mock<ICell> cellMock = new Mock<ICell>(MockBehavior.Strict);
            Assert.AreEqual("A21+B21+C21", formula.Resolve(cellMock.Object));
        }
        [TestMethod]
        public void TestAddAndMinus()
        {
            Reference ref1 = new Reference("A21");
            Reference ref2 = new Reference("B21");
            Reference ref3 = new Reference("C21");
            Formula formula = ref1 + ref2 - ref3;
            Mock<ICell> cellMock = new Mock<ICell>(MockBehavior.Strict);
            Assert.AreEqual("A21+B21-C21", formula.Resolve(cellMock.Object));
        }
        [TestMethod]
        public void TestAddAndMultiplication()
        {
            Reference ref1 = new Reference("A21");
            Reference ref2 = new Reference("B21");
            Reference ref3 = new Reference("C21");
            Formula formula = ref1 + ref2 * ref3;
            Mock<ICell> cellMock = new Mock<ICell>(MockBehavior.Strict);
            Assert.AreEqual("A21+B21*C21", formula.Resolve(cellMock.Object));
        }
        [TestMethod]
        public void TestMultiplicationAndAdd()
        {
            Reference ref1 = new Reference("A21");
            Reference ref2 = new Reference("B21");
            Reference ref3 = new Reference("C21");
            Formula formula = ref1 * ref2 + ref3;
            Mock<ICell> cellMock = new Mock<ICell>(MockBehavior.Strict);
            Assert.AreEqual("A21*B21+C21", formula.Resolve(cellMock.Object));
        }
        [TestMethod]
        public void TestMultiplicationOfAddition()
        {
            Reference ref1 = new Reference("A21");
            Reference ref2 = new Reference("B21");
            Reference ref3 = new Reference("C21");
            Formula formula = ref1 * (ref2 + ref3);
            Mock<ICell> cellMock = new Mock<ICell>(MockBehavior.Strict);
            Assert.AreEqual("A21*(B21+C21)", formula.Resolve(cellMock.Object));
        }
    }
}
